/*
 * Copyright (C) 2023 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose : Definition of ME handler: Main FTTR Unit  (65505)
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1) ME handler: Main FTTR Unit  (65505)
 */

#include "app_basic.h"
#include "omci_task.h"


MIB_TABLE_INFO_T gMibMainFttrUnitTableInfo;
MIB_ATTR_INFO_T  gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ATTR_NUM];
MIB_TABLE_MAIN_FTTR_UNIT_T gMibMainFttrUnitDefRow;
MIB_TABLE_OPER_T gMibMainFttrUnitOper;

static GOS_ERROR_CODE omci_mib_main_fttr_unit_reset(UINT32 args_num, ...)
{
    MIB_TABLE_MAIN_FTTR_UNIT_T mibMainFttrUnit;

    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: Main FTTR UNIT");

    MIB_Default(MIB_TABLE_MAIN_FTTR_UNIT_INDEX, &mibMainFttrUnit, sizeof(MIB_TABLE_MAIN_FTTR_UNIT_T));

    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_MAIN_FTTR_UNIT_INDEX, &mibMainFttrUnit, sizeof(MIB_TABLE_MAIN_FTTR_UNIT_T)));
    OMCI_MeOperCfg(MIB_TABLE_MAIN_FTTR_UNIT_INDEX, NULL, &mibMainFttrUnit, MIB_ADD,
        omci_GetOltAccAttrSet(MIB_TABLE_MAIN_FTTR_UNIT_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    return GOS_OK;

}



GOS_ERROR_CODE mibTable_init(MIB_TABLE_INDEX tableId)
{
    UINT8 proprietary_mib_cb_bitmask = 0;
    UINT8 isIgnore = 0;

    if(GOS_OK == omci_ignore_mib_table_check(OMCI_ME_CLASS_MAIN_FTTR_UNIT, OMCI_ME_CLASS_SUB_DEFAULT, &isIgnore))
    {
        if(isIgnore)
        {
            OMCI_PRINT("Ignore classId:%d", OMCI_ME_CLASS_MAIN_FTTR_UNIT);
            return GOS_FAIL;
        }
    }

    gMibMainFttrUnitTableInfo.Name = "MainFttrUnit";
    gMibMainFttrUnitTableInfo.ShortName = "MainFttrUnit";
    gMibMainFttrUnitTableInfo.Desc = "Main Fttr Unit";
    gMibMainFttrUnitTableInfo.ClassId = (UINT32)(OMCI_ME_CLASS_MAIN_FTTR_UNIT);
    gMibMainFttrUnitTableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_ONU);
    gMibMainFttrUnitTableInfo.StdType = (UINT32)(OMCI_ME_TYPE_PROPRIETARY);
    gMibMainFttrUnitTableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_SET | OMCI_ME_ACTION_GET);
    gMibMainFttrUnitTableInfo.pAttributes = &(gMibMainFttrUnitAttrInfo[0]);
	gMibMainFttrUnitTableInfo.attrNum = MIB_TABLE_MAIN_FTTR_UNIT_ATTR_NUM;
	gMibMainFttrUnitTableInfo.entrySize = sizeof(MIB_TABLE_MAIN_FTTR_UNIT_T);
	gMibMainFttrUnitTableInfo.pDefaultRow = &gMibMainFttrUnitDefRow;

    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityID";
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "AdminState";
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "OpState";
              
	gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
	gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Administrative state";
	gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Operational state";

    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
           
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;

    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
           
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;

    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
           
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;

    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_ADMINSTATE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMainFttrUnitAttrInfo[MIB_TABLE_MAIN_FTTR_UNIT_OPSTATE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
      

    memset(&gMibMainFttrUnitDefRow, 0x00, sizeof(gMibMainFttrUnitDefRow));


    memset(&gMibMainFttrUnitOper, 0x0, sizeof(MIB_TABLE_OPER_T));
	gMibMainFttrUnitOper.meOperDrvCfg = NULL;
	gMibMainFttrUnitOper.meOperConnCheck = NULL;
	gMibMainFttrUnitOper.meOperDump = omci_mib_oper_dump_default_handler;
	gMibMainFttrUnitOper.meOperConnCfg = NULL;
    gMibMainFttrUnitOper.meOperAlarmHandler = NULL;
    gMibMainFttrUnitOper.meOperTestHandler = NULL;
    gMibMainFttrUnitOper.meOperCb[PROPRIETARY_MIB_CB_RESET] = omci_mib_main_fttr_unit_reset;

	MIB_TABLE_MAIN_FTTR_UNIT_INDEX = tableId;
	MIB_InfoRegister(tableId,&gMibMainFttrUnitTableInfo,&gMibMainFttrUnitOper);

    proprietary_mib_cb_bitmask = (1 << PROPRIETARY_MIB_CB_RESET);
    MIB_Proprietary_Reg(tableId, proprietary_mib_cb_bitmask);

    return GOS_OK;
}
